package Dao;

import Entity.Officer;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class LogFrameDao {

    //登录，根据用户名和密码返回一个Officer，若未找到则返回null
    public static Officer Signin(String username, String password) throws IOException {
        ObjectMapper om = new ObjectMapper();

        File file = new File("files\\Officer.json");
        List<Officer> list = new ArrayList<>();
        if(file.exists() && file.length() != 0){
            list = om.readValue(file, new TypeReference<List<Officer>>() {});
        }
        for(Officer officer:list){
            if(officer.getUsername().equals(username) && officer.getPassword().equals(password)) return officer;
        }

        return null;
    }

}
